//
//  AddProjectExperienceViewController.m
//  InviteJob
//
//  Created by LangLang on 17/10/30.
//  Copyright © 2017年 Shui. All rights reserved.
//

#import "AddProjectExperienceViewController.h"

@interface AddProjectExperienceViewController ()<MCDatePickerViewDelegate>

@property (weak, nonatomic) IBOutlet UITextField *strProjectName;
@property (weak, nonatomic) IBOutlet UITextField *strPosition;
@property (weak, nonatomic) IBOutlet UITextField *strStartTime;
@property (weak, nonatomic) IBOutlet UITextField *strEndTime;
@property (strong, nonatomic) SZTextView *strProjectMsg;
@property (weak, nonatomic) IBOutlet UIView *projectMsgView;

@property (weak, nonatomic) IBOutlet UIView *showButton;

@property (nonatomic, strong) UIButton *navRightButton;

@property (nonatomic, assign ,getter=isYearShow) BOOL yearShow;

@end

@implementation AddProjectExperienceViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = strColor(@"f6f6f6");
    
    // 描述工作信息
    _strProjectMsg = [[SZTextView alloc] init];
    _strProjectMsg.placeholder = @"请输入你的项目描述";
    _strProjectMsg.font = [UIFont systemFontOfSize:14];
    [_projectMsgView addSubview:_strProjectMsg];
    [_strProjectMsg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@12);
        make.right.equalTo(@-12);
        make.top.equalTo(@15);
        make.bottom.equalTo(@-10);
    }];
    
    // right item
    self.navRightButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
    if (_indexEdit == 1) {
        TitleView(@"项目经验")
        _showButton.hidden = NO;
        [self.navRightButton setImage:[UIImage imageNamed:@"icon_news_delete"] forState:UIControlStateNormal];
        self.navRightButton.imageEdgeInsets = UIEdgeInsetsMake(0,15, 0, -15);
        // 传值
        _strProjectName.text = _editProjectName;
        _strPosition.text = _editPosition;
        _strStartTime.text = _editStartTime;
        _strEndTime.text = _editEndTime;
        _strProjectMsg.text = _editProjectMsg;
        
    }else{
        TitleView(@"添加项目经验")
        [self.navRightButton setTitle:@"提交" forState:UIControlStateNormal];
        self.navRightButton.titleEdgeInsets = UIEdgeInsetsMake(0,10, 0, -10);
        self.navRightButton.titleLabel.font = [UIFont systemFontOfSize:16];
    }
    
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:self.navRightButton];
    self.navigationItem.rightBarButtonItem = rightItem;
    // 事件绑定
    [self.navRightButton addTarget:self action:@selector(navActions) forControlEvents:UIControlEventTouchUpInside];
    
}

-(void)navActions{
    if (_indexEdit == 1) {
        
        _strProjectName.text = @"";
        _strPosition.text = @"";
        _strStartTime.text = @"";
        _strEndTime.text = @"";
        _strProjectMsg.text = @"";
        __weak typeof(self) weakSelf = self;
        if (weakSelf.projectExperience) {
            weakSelf.projectExperience(_strProjectName.text, _strPosition.text, _strStartTime.text, _strEndTime.text, _strProjectMsg.text);
            [self.navigationController popViewControllerAnimated:YES];
        }
    }else{
        
        if (_strProjectName.text.length==0) {
            SHuiMBhudTextTimeStr(@"请填写项目名称");
            return;
        }
        if (_strPosition.text.length==0) {
            SHuiMBhudTextTimeStr(@"请填写你的职位");
            return;
        }
        if (_strStartTime.text.length==0) {
            SHuiMBhudTextTimeStr(@"请选择开始时间");
            return;
        }
        if (_strEndTime.text.length==0) {
            SHuiMBhudTextTimeStr(@"请选择结束时间");
            return;
        }
        
        if (_strProjectMsg.text.length==0) {
            SHuiMBhudTextTimeStr(@"请输入项目描述");
            return;
        }
        
        __weak typeof(self) weakSelf = self;
        if (weakSelf.projectExperience) {
            weakSelf.projectExperience(_strProjectName.text, _strPosition.text, _strStartTime.text, _strEndTime.text, _strProjectMsg.text);
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
    
}

- (IBAction)btnSave:(id)sender {
    
    if (_strProjectName.text.length==0) {
        SHuiMBhudTextTimeStr(@"请填写项目名称");
        return;
    }
    if (_strPosition.text.length==0) {
        SHuiMBhudTextTimeStr(@"请填写你的职位");
        return;
    }
    if (_strStartTime.text.length==0) {
        SHuiMBhudTextTimeStr(@"请选择开始时间");
        return;
    }
    if (_strEndTime.text.length==0) {
        SHuiMBhudTextTimeStr(@"请选择结束时间");
        return;
    }
    
    if (_strProjectMsg.text.length==0) {
        SHuiMBhudTextTimeStr(@"请输入项目描述");
        return;
    }
    
    
    if (_strProjectName.text == _editProjectName &&
        _strPosition.text == _editPosition &&
        _strStartTime.text == _editStartTime &&
        _strEndTime.text == _editEndTime &&
        _strProjectMsg.text == _editProjectMsg) {
        [self.navigationController popViewControllerAnimated:YES];
        return;
    }
    
    __weak typeof(self) weakSelf = self;
    if (weakSelf.projectExperience) {
        weakSelf.projectExperience(_strProjectName.text, _strPosition.text, _strStartTime.text, _strEndTime.text, _strProjectMsg.text);
        [self.navigationController popViewControllerAnimated:YES];
    }
    
}

- (IBAction)btnInduction:(id)sender {
    
    MCDatePickerView *yearView = [[MCDatePickerView alloc] initWithFrame:CGRectZero type:XMGStyleTypeYearAndMonth];
    self.yearShow = YES;
    yearView.delegate = self;
    [yearView show];
    
}



- (IBAction)btnDeparture:(id)sender {
    
    MCDatePickerView *monthView = [[MCDatePickerView alloc] initWithFrame:CGRectZero type:XMGStyleTypeYearAndMonth];
    self.yearShow = NO;
    monthView.delegate = self;
    [monthView show];
 
    
}

-(void)didSelectDateResult:(NSString *)resultDate{
    if (self.isYearShow) {
        self.strStartTime.text = resultDate;
    }else{
        self.strEndTime.text = resultDate;
    }
    
}


@end
